<?php

class Application_Model_Contacts
{


}

class Db_Contacts extends Zend_Db_Table 
{ 

    protected $_name = 'contacts';

    public function check($where)
    {
	return $this->fetchAll($where)->count() > 0 ? true : false;
    }
    
    public function checkId($id)
    {
	return $this->check('id="'.$id.'"');
    }

    public function delContacts($id)
    {
	return ( $this->delete('id="'.$id.'"') > 0 ) ? true : false;
    }

    protected function set($id,$key,$value)
    {
	$db_users = new Db_Users();
	if ($db_users->checkId($id))
	{
	    if ($this->checkId($id))
	    {
    		$setdata[$key] =  $value;
		return $this->update($setdata,'id="'.$id.'"');
	    }
	    else
	    {
		$setdata = array
		(
		    'id' => $id,
		    $key => $value
		);
		return $this->insert($setdata);
	    }
	}
	else
	    return false;
    }

    public function getName($id)
    {
	return ($data=$this->fetchRow('id="'.$id.'"')) ? $data['name'] : false ;
    }
    
    public function setName($id,$value)
    {
	return $this->set($id,'name',$value);		
    }

    public function getICQ($id)
    {
	return ($data=$this->fetchRow('id="'.$id.'"')) ? $data['icq'] : false ;
    }
    
    public function setICQ($id,$value)
    {
	return $this->set($id,'icq',$value);		
    }

    public function getJabber($id)
    {
	return ($data=$this->fetchRow('id="'.$id.'"')) ? $data['jabber'] : false ;
    }
    
    public function setJabber($id,$value)
    {
	return $this->set($id,'jabber',$value);		
    }

    public function getSkype($id)
    {
	return ($data=$this->fetchRow('id="'.$id.'"')) ? $data['skype'] : false ;
    }
    
    public function setSkype($id,$value)
    {
	return $this->set($id,'skype',$value);		
    }

    public function getSIP($id)
    {
	return ($data=$this->fetchRow('id="'.$id.'"')) ? $data['sip'] : false ;
    }
    
    public function setSIP($id,$value)
    {
	return $this->set($id,'sip',$value);		
    }


}